package com.khiker.tree.binary_tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class P145_PreorderTraversal {
	public List<Integer> preorderTraversal(TreeNode root) {
		if (root == null) {
			return Collections.emptyList();
		}
		List<Integer> list = new ArrayList(128);
		traversal(root, list);
		return list;
	}

	private void traversal(TreeNode node, List<Integer> list) {
		if (node == null) {
			return;
		}
		traversal(node.left,list);
		traversal(node.right,list);
		list.add(node.val);
	}
}
